package com.jc.repository.generator.utils;

import com.google.common.base.Splitter;
import com.google.common.collect.Lists;
import com.jc.utils.DateFormatUtil;
import com.jc.utils.TimeUtils;
import org.apache.commons.lang3.StringUtils;

import java.io.File;
import java.util.Date;
import java.util.List;

/**
 * @author wangli
 * @create 2016-09-16 10:20
 * @description 代码生成工具的 映射信息
 */

public class MapperInfo {

    //    final String serviceBaseDir1 = "/Users/jcm002/wangli/code/useful/ssm/jeesite/src/main/java/com/thinkgem/jeesite/wang/service";
//    final String daoBaseDir1 = "/Users/jcm002/wangli/code/useful/ssm/jeesite/src/main/java/com/thinkgem/jeesite/wang/dao";
//    final String MAPPER_BASE_DIR = "/Users/jcm002/wangli/code/jc-java-wangli/jc-point-mall/jc-point-repository/src/main/java/com/jc/point/mapper";
//    final String mapperDomainDir = "/Users/jcm002/wangli/code/jc-java-wangli/jc-point-mall/jc-point-repository/src/main/java/com/jc/point/domain";
    //Domain 首字母类名大写 例如菜籽商城
    private String classNameCapital;

    //Domain 首字母类名小写
    private String className;

    //模块名称 例如 账户的目录下面的 account
    // 注意 一个模块目录下面可能有多个类, 例如AccountOptService 和 AccountPointAccountService
    private String moudleName;

    //字模块名称 例如 impl
    private String subModuleName = "impl";

    //mapper
    //例如 com.jc.mapper
    private String mapperPackageName;

    //dao包名 例如 com.jc.dao
    private String daoPackageName;

    //dao的根路径
    private String daoBaseDir;

    // service的包名
    // 例如/Users/jcm002/wangli/code/useful/ssm/jeesite/src/main/java/com/thinkgem/jeesite/wang/service
    private String servicePackageName;

    // service的根目录
    // 例如"/Users/jcm002/wangli/code/useful/ssm/jeesite/src/main/java/com/thinkgem/jeesite/wang/dao";
    private String serviceBaseDir;

    // domain 的包名
    // 例如 com.jc.domain
    private String domainPackageName;

    // 创建日期
    private String date;

    //dao接口层 类的后缀名 例如 AttributeDao
    private String dao = "Dao";

    //dao实现层 类的后缀名 例如 AttributeDaoImpl
    private String daoImpl = "DaoImpl";

    //service接口层 类的后缀名 例如 AttributeService
    private String service = "Service";

    //service实现层 类的后缀名 例如 AttributeServiceImpl
    private String serviceImpl = "ServiceImpl";


    //    public MapperInfo(File mapperFile, String mapperDomainDir , String daoBaseDir,String serviceBaseDir) {
    public MapperInfo(File mapperFile, GenerateBaseDir baseDir) {

        this.daoBaseDir = baseDir.getDao();
        this.serviceBaseDir = baseDir.getService();
        this.mapperPackageName = baseDir.getMapper();
        this.classNameCapital = mapperFile.getName().replaceAll("Mapper.java", "");
        this.className = StringUtils.uncapitalize(classNameCapital);

        List<String> pathStr = Lists.newArrayList(Splitter.on("/").trimResults().omitEmptyStrings().split(mapperFile.getParentFile().toString()));
        this.moudleName = pathStr.get(pathStr.size() - 1);

        String mapperFileDir = mapperFile.getParentFile().toString();
        this.mapperPackageName = mapperFileDir.substring(mapperFileDir.lastIndexOf("com")).replaceAll(File.separator, ".");


        this.daoPackageName = daoBaseDir.substring(daoBaseDir.lastIndexOf("com")).replace(File.separator, ".");
        this.servicePackageName = serviceBaseDir.substring(serviceBaseDir.lastIndexOf("com")).replace(File.separator, ".");
        this.domainPackageName = baseDir.getDomain().substring(baseDir.getDomain().lastIndexOf("com")).replace(File.separator, ".");


        this.date = DateFormatUtil.date2String(new Date(), DateFormatUtil.TIME_FORMAT_A);

    }

    public MapperInfo moudleName(String value) {
        this.moudleName = value;
        return this;
    }

    public String getClassName() {
        return className;
    }

    public void setClassName(String className) {
        this.className = className;

    }

    public String getClassNameCapital() {
        return classNameCapital;
    }

    public void setClassNameCapital(String classNameCapital) {
        this.classNameCapital = classNameCapital;
    }

    public String getMoudleName() {
        return moudleName;
    }

    public void setMoudleName(String moudleName) {
        this.moudleName = moudleName;
    }

    public String getSubModuleName() {
        return subModuleName;
    }

    public void setSubModuleName(String subModuleName) {
        this.subModuleName = subModuleName;
    }

    public String getMapperPackageName() {
        return mapperPackageName;
    }

    public void setMapperPackageName(String mapperPackageName) {
        this.mapperPackageName = mapperPackageName;
    }

    public String getDaoPackageName() {
        return daoPackageName;
    }

    public void setDaoPackageName(String daoPackageName) {
        this.daoPackageName = daoPackageName;
    }

    public String getDaoBaseDir() {
        return daoBaseDir;
    }

    public void setDaoBaseDir(String daoBaseDir) {
        this.daoBaseDir = daoBaseDir;
    }

    public String getServicePackageName() {
        return servicePackageName;
    }

    public void setServicePackageName(String servicePackageName) {
        this.servicePackageName = servicePackageName;
    }

    public String getServiceBaseDir() {
        return serviceBaseDir;
    }

    public void setServiceBaseDir(String serviceBaseDir) {
        this.serviceBaseDir = serviceBaseDir;
    }

    public String getDomainPackageName() {
        return domainPackageName;
    }

    public void setDomainPackageName(String domainPackageName) {
        this.domainPackageName = domainPackageName;
    }

    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }

    public String getDao() {
        return dao;
    }

    public void setDao(String dao) {
        this.dao = dao;
    }

    public String getDaoImpl() {
        return daoImpl;
    }

    public void setDaoImpl(String daoImpl) {
        this.daoImpl = daoImpl;
    }

    public String getService() {
        return service;
    }

    public void setService(String service) {
        this.service = service;
    }

    public String getServiceImpl() {
        return serviceImpl;
    }

    public void setServiceImpl(String serviceImpl) {
        this.serviceImpl = serviceImpl;
    }
}
